package com.suzhe.ymall.product.service.impl;


import com.suzhe.ymall.product.service.IProductEhcacheService;
import com.suzhe.ymall.product.vo.SpuVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class ProductEhcacheServiceImpl implements IProductEhcacheService {
    private static final String CACHE_NAME = "spuVos";

    @Override
    @Cacheable(value=CACHE_NAME,key="'spuVo_'+#id")
    public SpuVo get(Integer id) {
        log.info("Ehcache缓存中无数据：{}",id);
        return null;
    }

    @CachePut(value = CACHE_NAME,key = "'product_'+#product.getId()")
    @Override
    public SpuVo save(SpuVo spuVo) {
        log.info("放入Ehcache缓存：{}",spuVo.getId());
        return spuVo;
    }

    @CacheEvict(value = CACHE_NAME,key = "'spuVo_'+#id")
    @Override
    public void delete(Integer id) {
        log.info("清除Ehcache缓存：{}",id);
    }
}
